<?php
/**
 * Created by PhpStorm.
 * User: Thans
 * Date: 2018/8/12
 * Time: 17:02
 */

namespace app\admin\controller;

use app\admin\facade\Language;
use app\common\controller\Admin;
use think\facade\Request;

class LanguageController extends Admin
{
    /**
     * @title 增加语言
     * @desc  {"0":"接口地址：","1":"请求方式：GET","2":"接口备注："}
     * @param {"name":"","type":"string","required":false,"default":"","desc":""}
     * @return {"name":"","type":"jsoon","required":true,"desc":"","level":1}
     */
    public function save()
    {
        $data   = Request::param('');
        $result = $this->validate($data, 'app\admin\validate\LanguageValidate');
        if (true !== $result) {
            // 验证失败 输出错误信息
            return ['code' => 4001, 'msg' => $result, 'data' => []];
        }
        $res = Language::save($data);
        return $res;
    }

    /**
     * @title 更新语言
     * @desc  {"0":"接口地址：","1":"请求方式：GET","2":"接口备注："}
     * @param {"name":"","type":"string","required":false,"default":"","desc":""}
     * @return {"name":"","type":"jsoon","required":true,"desc":"","level":1}
     */
    public function update($id)
    {
        $data   = Request::param('');
        $result = $this->validate($data, 'app\admin\validate\LanguageValidate');
        if (true !== $result) {
            // 验证失败 输出错误信息
            return ['code' => 4001, 'msg' => $result, 'data' => []];
        }
        $res = Language::update($id, $data);
        return $res;
    }

    /**
     * @title 读取语言
     * @desc  {"0":"接口地址：","1":"请求方式：GET","2":"接口备注："}
     * @param {"name":"","type":"string","required":false,"default":"","desc":""}
     * @return {"name":"","type":"jsoon","required":true,"desc":"","level":1}
     */
    public function read($id)
    {
        return Language::getById($id);
    }

    /**
     * @title 删除语言
     * @desc  {"0":"接口地址：","1":"请求方式：GET","2":"接口备注："}
     * @param {"name":"","type":"string","required":false,"default":"","desc":""}
     * @return {"name":"","type":"jsoon","required":true,"desc":"","level":1}
     */
    public function delete($id)
    {
        return Language::delete($id);
    }
    public function toggle($id)
    {
        $this->results(Language::toggle($id));
    }

    /**
     * @title 获取列表
     * @desc  {"0":"接口地址：","1":"请求方式：GET","2":"接口备注："}
     * @param {"name":"","type":"string","required":false,"default":"","desc":""}
     * @return {"name":"","type":"jsoon","required":true,"desc":"","level":1}
     */
    public function index()
    {
        $page    = Request::get('page') ?: '1';
        $limit   = Request::get('limit') ?: '10';
        $keyword = Request::get('keyword') ?: '';
        $res     = Language::getList($page, $limit, $keyword);
        $this->results($res);
    }

}
